package com.example.administrator.funchat.adapter;

import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.funchat.model.Friend_information;
import com.example.administrator.funchat.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 朋友圈适配器
 * Created by Administrator on 2016/6/24.
 */
public class FriendAdapter extends ArrayAdapter<Friend_information> {

    private int resourceId;
    private List<Friend_information> friendList = new ArrayList<>();

    public FriendAdapter(FragmentActivity activity, int friend_item) {
        super(activity, friend_item);
        this.resourceId = friend_item;
    }

    @Override
    public int getCount() {
        return friendList.size();
    }

    @Override
    public Friend_information getItem(int position) {
        return friendList.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Friend_information information = getItem(position);

        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(resourceId, null);
            viewHolder = new ViewHolder();
            viewHolder.infoFromImage = (ImageView) convertView.findViewById(R.id.friend_head_image);
            viewHolder.pushImage = (ImageView) convertView.findViewById(R.id.push_image);
            viewHolder.pushInfo = (ImageView) convertView.findViewById(R.id.push_info);
            viewHolder.foot = (ImageView) convertView.findViewById(R.id.foot);
            viewHolder.heart = (ImageView) convertView.findViewById(R.id.heart);
            viewHolder.infoFrom = (TextView) convertView.findViewById(R.id.info_from);
            viewHolder.endTime = (TextView) convertView.findViewById(R.id.end_time);
            viewHolder.baoti = (TextView) convertView.findViewById(R.id.biaoti);
            viewHolder.textContent = (TextView) convertView.findViewById(R.id.textContent);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.infoFromImage.setImageResource(information.getInfoFromId());
        viewHolder.pushImage.setImageResource(information.getPushImage());
        viewHolder.pushInfo.setImageResource(information.getPushInfo());
        viewHolder.foot.setImageResource(information.getFoot());
        viewHolder.heart.setImageResource(information.getHeart());
        viewHolder.infoFrom.setText(information.getInfoFrom());
        viewHolder.endTime.setText(information.getEndTime());
        viewHolder.baoti.setText(information.getBiaoti());
        viewHolder.textContent.setText(information.getTextContent());
        return convertView;

    }

    class ViewHolder {
        ImageView infoFromImage;
        ImageView pushImage;
        ImageView pushInfo;
        ImageView foot;
        ImageView heart;
        TextView infoFrom;
        TextView endTime;
        TextView baoti;
        TextView textContent;

    }

    public void load() {
        Friend_information haoyou = new Friend_information("小王", "2小时前", "我就随便写写",
                "he Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative," +
                        " hypermedia information systems. HTTP is the foundation o",
                R.mipmap.xiaoxiong, R.mipmap.sleeppeple, R.mipmap.push_icon, R.mipmap.foot_icon, R.mipmap.heart_icon);
        friendList.add(haoyou);

        Friend_information pengyou = new Friend_information("樱木花道", "6小时前", "我就随便看看",
                "collaborative, hypermedia information systems. HTTP is the foundation o",
                R.mipmap.people01, R.mipmap.sleeppeple, R.mipmap.push_icon, R.mipmap.foot_icon, R.mipmap.heart_icon);
        friendList.add(pengyou);

    }
}


